<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card shadow="never">
        <!-- 学科 -->
            <el-form>
            <el-form-item label="学科名称" label-width="80px">
           <el-col type="flex" justify="start" :span="4">
          <el-input v-model="subjectName"></el-input>
           </el-col>
               <el-button size="small">清除</el-button>
               <el-button size="small" type="primary">搜索</el-button>
            </el-form-item>
            </el-form>
        <template>
        <div class="qwer">数据一共 {{randomsListCounts}} 条</div>
        </template>
      </el-card>
      <el-tabs type="border-card">
        <el-table :data="sublist" border style="width: 100%">
          <el-table-column prop="id" label="序号" width="48px"></el-table-column>
          <el-table-column prop="subjectName" label="学科名称" width="180"></el-table-column>
          <el-table-column prop="username" label="创建者"></el-table-column>
          <el-table-column width="180px" prop="addDate" label="创建日期">
            <template v-slot="{row}">
 <!--     格式化时间  $moment(要格式化的对象).format("要定义的格式") -->
              <span>{{$moment(row.addDate).format("YYYY-MM-DD HH:MM:SS")}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="isFrontDisplay" label="前台是否显示">
            <template v-slot="{row}">
              <span>{{row.isFrontDisplay===1?"是":"否"}} </span>
            </template>
          </el-table-column>
          <el-table-column prop="twoLevelDirectory" label="二级目录">
          </el-table-column>
          <el-table-column prop="tags" label="标签"> </el-table-column>
          <el-table-column prop="totals" label="题目数量"> </el-table-column>
          <el-table-column prop="" label="操作" width="248px">
            <template #default="{row}">
              <span><el-link type="primary" >学科分类</el-link></span>
              <span><el-link type="primary" >学科标签</el-link></span>
              <span @click="dialogVisible1(row.subjectName, row.id)"><el-link type="primary" >修改</el-link></span>
              <el-button type="text" @click="del(row.id)">删除</el-button>

            </template>
          </el-table-column>
        </el-table>
        <!--   分页 -->
       <el-row type="flex" justify="end">
         <el-pagination
             @size-change="handleSizeChange"
             @current-change="handleCurrentChange"
             :current-page="currentPage4"
             :page-sizes="[5, 10, 20, 30]"
             :page-size="queryParams.pagesize"
             layout="sizes, prev, pager, next, jumper"
             :total="randomsListCounts">
           </el-pagination>
       </el-row>
      </el-tabs>
    </div>
    <!-- 修改  弹窗 -->
    <!-- 双向绑定v-modal触发的是父组件input事件，.sync触发的是父组件的update事件. -->
    <el-dialog
      title="修改学科"
      :visible.sync="dialogVisible"
      modal-append-to-body
      width="30%"
    >
      <el-form>
        <el-form-item label="学科名称">
          <el-input v-model="TextField"></el-input>
        </el-form-item>
      </el-form>
      <span>
        <el-button @click="quxiao">取 消</el-button>
        <el-button type="primary" @click="queding">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { sublist, update, remove } from '../../api/hmmm/subjects'
export default {
  data () {
    return {
      queryParams: {
        departmentId: null,
        page: 1, // 当前页码
        pagesize: 5,
        keyword: '' // 模糊搜索字段
      },

      page: 1, // 当前页码
      pagesize: 5,
      total: 0,
      timer: null,
      randomsListCounts: null,
      Rlist: [],
      currentPage4: 1, //  打来默认 显示 第一页
      dialogVisible: false,
      TextField: '',
      subjectID: 1,
      tagName: 5,
      id: '',
      subjectName: '',
      creator: '',
      username: '',
      sublist: [],
      subjectIDedit: ''

    }
  },
  //  获取 调接口 都可以用 created
  created () {
    this.getsublist()
  },
  methods: {
    //     获取列表
    async getsublist () {
      const res3 = await sublist({ page: this.page, pagesize: this.pagesize })
      this.sublist = res3.data.items
      //   页码 总数
      this.randomsListCounts = res3.data.counts
      // this.Rlist = res3.data.items
    },
    //   修改 学科
    /* 拿到 学科名字 和 id   */
    dialogVisible1 (subjectName, id) {
      this.TextField = subjectName
      this.subjectIDedit = id
      this.dialogVisible = true //  隐藏 弹窗
    },
    //  点击确定 关闭 弹窗
    async queding () {
      this.dialogVisible = false //  显示 弹窗
      const data = {
        id: this.subjectIDedit,
        subjectName: this.TextField, //  输入框 的数据 改变新的 内容 传给  subjectName
        isFrontDisplay: 0
      }
      await update(data)
      this.getsublist()
    },
    //  取消 确认 关闭修改弹窗
    quxiao () {
      this.dialogVisible = false
    },
    //  删除 功能
    del (id) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        await remove({ id })
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
        this.getsublist()
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    //    模糊搜索 功能

    // 分页器
    //  每页多少条

    handleCurrentChange (page) {
      this.page = page
      // console.log(page)
      this.getsublist()
    },
    //  当前那一页
    handleSizeChange (val) {
      this.pagesize = val
      // console.log(val)
      this.getsublist()
    }
    //   模糊搜索

  }
}
</script>

<style scoped>
.el-button--medium {
  margin-left: 10px;
}

.qwer {
  height: 34px;
  background-color: #f4f4f5;
  display: flex;
  align-items: center;
  margin-right: 5px;
  font-size: 8px;
  color: #909399;
}
.border {
  padding: 14px !important;
}
body.el-card__body{

}
.cell span{
  margin-left: 10px;
}
</style>
